package com.free.mini.core.serve.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.free.mini.core.serve.entity.UserToken;
import com.free.mini.core.serve.mapper.UserTokenMapper;
import com.free.mini.core.serve.service.IUserTokenService;

import lombok.RequiredArgsConstructor;

/**
 * 用户token表 Service实现
 *
 * @author dongsufeng
 * @date 2023-08-02 17:51:40
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken> implements IUserTokenService {

    private final UserTokenMapper userTokenMapper;

    @Override
    public IPage<UserToken> findUserToken( UserToken userToken) {
        LambdaQueryWrapper<UserToken> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        Page<UserToken> page = new Page<>(0,1);
        return this.page(page, queryWrapper);
    }

    @Override
    public List<UserToken> findUserTokens(UserToken userToken) {
	    LambdaQueryWrapper<UserToken> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createUserToken(UserToken userToken) {
        this.save(userToken);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateUserToken(UserToken userToken) {
        this.saveOrUpdate(userToken);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteUserToken(UserToken userToken) {
        LambdaQueryWrapper<UserToken> wrapper = new LambdaQueryWrapper<>();
	    // TODO 设置删除条件
	    this.remove(wrapper);
	}
}
